<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>智慧社区后台-志愿者招募</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.min.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/plugins/bootstrap-table/css/bootstrap-table.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/plugins/bootstrap-switch/css/bootstrap-switch.min.css">
</head>
<style>
</style>
<body style="padding-bottom: 90px; background-color: #ECF0F5;">
	<section class="content" style="margin: 15px; background-color: white;">
		<div class="row">
			<div class="col-sm-12">
				<table id="table">
					<thead style="background-color: #00C0EF">
						<tr style="background-color: #00C0EF">
							<th class="text-center" data-field=""></th>
							<th class="text-center" data-field="recruitInfoTheme">主题</th>
							<th class="text-center" data-field="recruitChargeName">发起人</th>
							<th class="text-center" data-field="recruitTel">联系方式</th>
							<th class="text-center" data-field="recruitEndTime">结束时间</th>
							<th class="text-center" data-field="vrId">操作</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
	</section>
	<!-- Large modal -->
	<div id="modal" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
		<div class="modal-dialog modal-lg" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">志愿者招募</h4>
				</div>
				<div class="modal-body">
					<div class="form-group">
						<label for="recruit_info_theme" class="control-label">招募主题:</label> <input type="text" class="form-control" id="recruit_info_theme">
					</div>
					<div class="form-group">
						<%-- <label for="recruit_info_theme" class="control-label">标题图片:</label> 
		                <img id="image" class="cover-radius"  src="${pageContext.request.contextPath}/img/upload.jpg"
		                           width="50px;" style="cursor: pointer;" />
		                <input id="picture_upload" name="file" type="file" onchange="upload_cover(this)"
		                           style="position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; opacity: 0; cursor: pointer;"/>
		                <small class="help-block cover-tips" style="color: #dd4b39;display: none;">请上传照片</small> --%>

						<label for="recruit_info_theme" class="control-label">标题图片:</label>
						<button id="imgBtn" class="btn btn-primary glyphicon glyphicon-plus" onclick="imgFile.click();">上传图片</button>
						<img id="image" class="cover-radius" src="${pageContext.request.contextPath}/img/upload.jpg" width="150px;" style="cursor: pointer;" onclick="imgFile.click();" /> <input type="file" class="form-control" style="display: none;" name="imgFile" id="imgFile" onchange="fileChange()"> <small class="help-block cover-tips" style="color: #dd4b39; display: none;">请上传照片</small>
						<!-- <input type="text" class="form-control" id="upload_file_img" readonly="readonly"
	                           onclick="imgFile.click();" > -->
					</div>
					<div class="form-group">
						<label for="recruit_tel" class="control-label">联系方式:</label> <input type="text" class="form-control" id="recruit_tel">
					</div>
					<div class="form-group">
						<label for="recruit_charge_name" class="control-label">发起人:</label> <input type="text" class="form-control" value="${sessionScope.userAccount}" id="recruit_charge_name">
					</div>
					<div class="form-group">
						<label for="recruit_end_time" class="control-label">招募结束时间:</label> <input type="text" class="form-control" id="recruit_end_time">
					</div>
					<div class="form-group">
						<label for="recruit_info_content" class="control-label">招募内容描述：</label>
						<textarea rows="3" cols="20" class="form-control" id="recruit_info_content">
						
						</textarea>
					</div>
					<div class="form-group">
						<label for="recruit_info_content" class="control-label">是否启用免责任条款： <input id="escapeState" name="escapeState" type="checkbox" data-size="small">
						</label>
						<!-- 						<textarea rows="3" cols="20" class="form-control" id="escapeClause"> -->
						<!-- 						</textarea> -->
						<textarea style="width: 100%; height: 500px;" class="form-control" rows="30" id="escapeClause" name="kindEditor_content"></textarea>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button id="closeBtn" type="button" class="btn btn-primary" onclick="submitRecruit();">提交</button>
				</div>
			</div>
		</div>
	</div>
	<div id="enrollModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">志愿者报名</h4>
				</div>
				<div class="modal-body">
					<div class="row">
						<div class="col-sm-12">
							<table class="table table-condensed">
								<thead style="background-color: #00C0EF">
									<tr style="background-color: #00C0EF">
										<th class="text-center" data-field="recruitInfoTheme">姓名</th>
										<th class="text-center" data-field="recruitChargeName">联系方式</th>
										<th class="text-center" data-field="recruitTel">报名时间</th>
									</tr>
								</thead>
								<tbody id="enrollTable">

								</tbody>
							</table>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" onclick="exportData();">导出数据</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				</div>
			</div>
		</div>
	</div>
</body>
<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-export.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/tableExport.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-toolbar.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-filter-control.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>
<script src="${pageContext.request.contextPath}/js/ajaxfileupload.js"></script>
<script src="${pageContext.request.contextPath}/js/date.js"></script>
<!-- layer -->
<script src="${pageContext.request.contextPath}/plugins/layer/2.4/layer.js"></script>
<script src="${pageContext.request.contextPath}/plugins/laydate/laydate.js"></script>
<!-- kindeditor 编辑器 -->
<script charset="utf-8" src="${pageContext.request.contextPath}/kindeditor-4.1.10/kindeditor.js"></script>
<script charset="utf-8" src="${pageContext.request.contextPath}/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script>
	var editor;
	var flag = false;
	var imgUrl = "";
	//var state=${State};
	laydate.render({
		elem : '#recruit_end_time', //指定元素
		// 		type : 'datetime',
		min : (new Date()).Format("yyyy-MM-dd")
	});
	var vrId = "";
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="kindEditor_content"]', {
			items : [ 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter',
					'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', '|',
					'fullscreen', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|',
					'image', 'multiimage', 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak', 'anchor', 'link', 'unlink', '|', 'about' ], //配置kindeditor编辑器的工具栏菜单项
			cssPath : 'kindeditor-4.1.10/plugins/code/prettify.css',
			allowFileManager : true,
			uploadJson : '${pageContext.request.contextPath}/upload_img.do', //上传
			fileManagerJson : '${pageContext.request.contextPath}/mien_file_manager.do', // 文件管理
			filterMode : true, //是否启用过滤模式(编辑文本框中是否可以出现控件显示)
			htmlTags : {
				span : [ '.color', '.background-color', '.font-size', '.font-family', '.background', '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height' ],
				font : [ 'id', 'class', 'color', 'size', 'face', '.background-color' ],
				a : [ 'id', 'class', 'href', 'target', 'name' ],
				embed : [ 'id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess' ],
				img : [ 'id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border' ],
				'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [ 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background', '.font-weight',
						'.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left' ],
				pre : [ 'id', 'class' ],
				hr : [ 'id', 'class', '.page-break-after' ],
				'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : [ 'id', 'class' ],
				iframe : [ 'id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height' ]
			},
			allowFileManager : true,
			allowUpload : false, //允许上传图片
			imageUploadJson : '/saveImg', //服务端上传图片处理URI
			resizeType : 0,//使其不可以拖动 
			afterCreate : function() {
				var self = this;
				K.ctrl(document, 13, function() {
					self.sync();
				});
				K.ctrl(self.edit.doc, 13, function() {
					self.sync();
				});
			},
			afterBlur : function() {
				this.sync();
			}
		});
		editor.readonly(true);
	});
	function actionFormatter(value, row, index) {
		//if(state==1){
		if (row.recruitState == 0) {
			return [ "<button class='btn btn-success btn-xs glyphicon glyphicon-user' onclick='showEnroll(\"" + row.vrId + "\");'>查看报名</button>",
					"&nbsp;<button class='btn btn-primary btn-xs glyphicon glyphicon-pencil' onclick='showModal(\"" + row.vrId + "\");'>编辑信息</button>",
					"&nbsp;<button class='btn btn-warning btn-xs glyphicon glyphicon-trash' onclick='cancelRecruit(\"" + row.vrId + "\")'>取消招募</button>", ].join('');
		} else if (row.recruitState == 1) {
			return [ "<button class='btn btn-success btn-xs glyphicon glyphicon-user' onclick='showEnroll(\"" + row.vrId + "\");'>查看报名</button>",
					"&nbsp;<button class='btn btn-primary btn-xs glyphicon glyphicon-pencil' onclick='showInfo(\"" + row.vrId + "\");'>查看信息</button>",
					"&nbsp;<button class='btn btn-info btn-xs glyphicon glyphicon-trash'>&nbsp;已结束</button>", ].join('');
		} else if (row.recruitState == 2) {
			return [ "<button class='btn btn-success btn-xs glyphicon glyphicon-user' onclick='showEnroll(\"" + row.vrId + "\");'>查看报名</button>",
					"&nbsp;<button class='btn btn-primary btn-xs glyphicon glyphicon-pencil' onclick='showInfo(\"" + row.vrId + "\");'>查看信息</button>",
					"&nbsp;<button class='btn btn-danger btn-xs glyphicon glyphicon-trash'>&nbsp;已取消</button>", ].join('');
		}
		/* }else if(state==2){
			return [ "<button class='btn btn-success btn-xs glyphicon glyphicon-user' onclick='showEnroll(\"" + row.vrId + "\");'>添加风采</button>"].join('');
		} */

	}
	var table_dataset = [ {
		field : 'id',
		checkbox : true,
	}, {
		field : 'recruitInfoTheme',
		align : 'center',
	}, {
		field : 'recruitChargeName',
		align : 'center',
	}, {
		field : 'recruitTel',
		align : 'center',
	}, {
		field : 'recruitEndTime',
		align : 'center',
		formatter : function actionFormatter(value, row, index) {
			return (new Date(row.recruitEndTime)).Format("yyyy-MM-dd");
		}
	}, {
		align : 'center',
		width : 300,
		formatter : actionFormatter,
	} ];
	$('#table').bootstrapTable(
			{
				url : "${pageContext.request.contextPath}/selectVolunteerRecruit",
				idField : "vrId",
				columns : table_dataset,
				striped : true, //是否显示行间隔色
				pagination : true, //是否显示分页
				pageSize : 10, //每页的记录行数
				pageList : [ 10, 25, 50, 100 ], //可供选择的每页的行数
				search : false, //是否显示搜索
				showRefresh : true,
				sidePagination : "server", //表示服务端请求  
				queryParamsType : "limit",
				queryParams : function queryParams(params) { //设置查询参数  
					var param = {
						offset : params.offset,
						limit : params.limit,
						kod : $("#kod").val(),
						kodType : $("#kodType").val()
					};
					return param;
				},
				toolbar : "<button style='float:left;' class='btn btn-primary glyphicon glyphicon-plus' onclick='showModal(\"" + '' + "\");'>新增数据</button>"
						+ "<div  style='width:250px;float:left;margin-top:2px;margin-left:20px;'>" + "<select id='kodType' name='stateType' class='form-control' onchange='Querry()'>"
						+ "<option value=''>全部</option>" + "<option value=0>正在招募</option>" + "<option value=1>已结束</option>" + "<option value=2>取消招募</option>" + "</select></div>"
						+ "<div class='input-group' style='width:250px;float:right;margin-top:2px;margin-left:20px;'><input type='text' class='form-control' placeholder='请输入主题' id='kod' name='kod'>"
						+ "<span class='input-group-btn'><button class='btn btn-default' type='button' onclick='Querry(\"" + '' + "\");'>查询</button></span></div>",

				icons : {
					paginationSwitchDown : 'glyphicon-collapse-down icon-chevron-down',
					paginationSwitchUp : 'glyphicon-collapse-up icon-chevron-up',
					refresh : 'glyphicon-refresh icon-refresh',
					toggle : 'glyphicon-list-alt icon-list-alt',
					columns : 'glyphicon-th icon-th',
					detailOpen : 'glyphicon-plus icon-plus',
					detailClose : 'glyphicon-minus icon-minus',
					"export" : 'glyphicon-export icon-share'
				},
				showExport : true,
				exportDataType : 'basic',
				exportTypes : [ 'json', 'xml', 'csv', 'txt', 'sql', 'excel' ]
			});

	$(function() {
		// 		$("#escapeClause").hide();
		$("#escapeState").bootstrapSwitch({
			onText : "启用",
			offText : "禁用",
			onColor : "info",
			offColor : "warning",
			size : "small",
			state : false,
			onSwitchChange : function(event, state) {
				flag = state;
				if (state) {
					// 					$("#escapeClause").show();
					editor.readonly(false);
				} else {
					// 					$("#escapeClause").hide();
					editor.readonly(true);
					editor.html('');
				}
			}
		});
		$("#image").hide();
	});

	function showModal(id) {
		enableChiose(false);
		if (id == "") {
			vrId = '';
			$("#recruit_info_theme").val('');
			imgUrl = "";
			$("#imgBtn").show();
			$('#image').attr('src', '');
			$("#recruit_tel").val('');
			$("#recruit_charge_name").val('');
			$("#recruit_end_time").val('');
			$("#recruit_info_content").val('');
			flag = false;
			$("#escapeState").bootstrapSwitch('state', false, true);
			// 			$("#escapeClause").hide();
			editor.readonly(true);
			// 			$("#escapeClause").val('');
			editor.html('')
			$('#modal').modal({
				backdrop : 'static',
				keyboard : false
			});
		} else {
			editor.html('')
			vrId = id;
			$.ajax({
				url : "${pageContext.request.contextPath}/selectVolunteerRecruitById",
				type : "get",
				data : {
					vrId : vrId
				},
				dataType : "json",
				success : function(data) {
					var recruit = data.result;
					$("#recruit_info_theme").val(recruit.recruitInfoTheme);
					$('#image').attr('src', '');
					if (recruit.recruitInfoPic != null && recruit.recruitInfoPic != "") {
						imgUrl = recruit.recruitInfoPic;
						$('#image').attr('src', '${pageContext.request.contextPath}/' + recruit.recruitInfoPic);
						$("#imgBtn").hide();
						$('#image').show();
					} else {
						$("#imgBtn").show();
					}
					$("#recruit_tel").val(recruit.recruitTel);
					$("#recruit_charge_name").val(recruit.recruitChargeName);
					$("#recruit_end_time").val((new Date(recruit.recruitEndTime)).Format("yyyy-MM-dd"));
					$("#recruit_info_content").val(recruit.recruitInfoContent);
					if (recruit.escapeState == 0) {
						flag = false;
						$("#escapeState").bootstrapSwitch('state', false, true);
						// 						$("#escapeClause").hide();
						editor.readonly(true);
					} else if (recruit.escapeState == 1) {
						flag = true;
						$("#escapeState").bootstrapSwitch('state', true, true);
						// 						$("#escapeClause").show();
						editor.readonly(false);
						// 						$("#escapeClause").val(recruit.escapeClause);
						editor.html(recruit.escapeClause)
					}
					$('#modal').modal({
						backdrop : 'static',
						keyboard : false
					});
				},
				error : function() {
					layer.msg('系统异常!', {
						icon : 2,
						time : 800
					});
				}
			});
		}
	}

	function showInfo(id) {
		vrId = id;
		$.ajax({
			url : "${pageContext.request.contextPath}/selectVolunteerRecruitById",
			type : "get",
			data : {
				vrId : vrId
			},
			dataType : "json",
			success : function(data) {
				var recruit = data.result;
				$("#recruit_info_theme").val(recruit.recruitInfoTheme);
				$('#image').attr('src', '');
				if (recruit.recruitInfoPic != null && recruit.recruitInfoPic != "") {
					imgUrl = recruit.recruitInfoPic;
					$('#image').attr('src', '${pageContext.request.contextPath}/' + recruit.recruitInfoPic);
					$("#imgBtn").hide();
					$('#image').show();
				} else {
					$("#imgBtn").show();
				}
				$("#recruit_tel").val(recruit.recruitTel);
				$("#recruit_charge_name").val(recruit.recruitChargeName);
				$("#recruit_end_time").val(recruit.recruitEndTime);
				$("#recruit_info_content").val(recruit.recruitInfoContent);
				if (recruit.escapeState == 0) {
					flag = false;
					$("#escapeState").bootstrapSwitch('state', false, true);
					// 					$("#escapeClause").hide();
					editor.readonly(true);
				} else if (recruit.escapeState == 1) {
					flag = true;
					$("#escapeState").bootstrapSwitch('state', true, true);
					// 					$("#escapeClause").show();
					editor.readonly(false);
					// 					$("#escapeClause").val(recruit.escapeClause);
					editor.html(recruit.escapeClause)
				}
				enableChiose(true);
				$('#modal').modal({
					backdrop : 'static',
					keyboard : false
				});
			},
			error : function() {
				layer.msg('系统异常!', {
					icon : 2,
					time : 800
				});
			}
		});
	}

	function enableChiose(type) {
		$("#recruit_info_theme").attr("disabled", type);
		$("#image").attr("disabled", type);
		$("#recruit_tel").attr("disabled", type);
		$("#recruit_charge_name").attr("disabled", type);
		$("#recruit_end_time").attr("disabled", type);
		$("#recruit_info_content").attr("disabled", type);
		$("#escapeState").bootstrapSwitch('disabled', type);
		// 		$("#escapeClause").attr("disabled", type);
		editor.readonly(type)
		// 		$("#escapeClause").val('');
		// 		editor.html('')
		$('#image').attr('disabled', type);
		$('#imgBtn').attr('disabled', type);
		if (type) {
			$("#closeBtn").hide();
		} else {
			$("#closeBtn").show();
		}
	}
	//显示招募报名信息
	function showEnroll(id) {
		vrId = id;
		$.ajax({
			url : "${pageContext.request.contextPath}/selectVolunteerEnroll",
			type : "get",
			data : {
				vrId : vrId
			},
			dataType : "json",
			success : function(data) {
				var list = data.result;
				var html = "";
				if (list.length == 0) {
					html = "<tr><td colspan='3' class='text-center'>暂无人报名</td></tr>"
				}
				for (var i = 0; i < list.length; i++) {
					html += "<tr><td class='text-center'>" + list[i].enrollName + "</td><td class='text-center'>" + list[i].enrollTel + "</td><td class='text-center'>"
							+ (new Date(list[i].enrollTime)).Format("yyyy-MM-dd hh:mm:ss") + "</td></tr>";
				}
				$("#enrollTable").html(html);
				$('#enrollModal').modal({
					backdrop : 'static',
					keyboard : false
				});
			},
			error : function() {
				layer.msg('系统异常!', {
					icon : 2,
					time : 800
				});
			}
		});
	}

	//保存
	function submitRecruit() {
		$("#closeBtn").button('loading');
		var recruitInfoTheme = $('#recruit_info_theme').val();
		var recruitInfoPic = imgUrl;
		var recruitTel = $('#recruit_tel').val();
		var recruitChargeName = $("#recruit_charge_name").val();
		var recruitEndTime = $('#recruit_end_time').val();
		var recruitInfoContent = $('#recruit_info_content').val();
		if (recruitInfoTheme === '' || recruitInfoPic === '' || recruitTel === '' || recruitChargeName === '' || recruitEndTime === '') {
			layer.alert("新增的数据中填写不完整！");
			$("#closeBtn").button('reset');
			return false;
		}
		if (!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(recruitTel))) {
			layer.alert("联系方式格式不正确！");
			$("#closeBtn").button('reset');
			return false;
		}
		var escapeState = 0;
		var escapeClause = null;
		if (flag) {
			escapeState = 1;
			escapeClause = $("#escapeClause").val();
			if (editor.isEmpty()) {
				layer.alert("新增的数据中填写不完整!");
				$("#closeBtn").button('reset');
				return false;
			}
		}

		var url = vrId === '' ? '${pageContext.request.contextPath}/insertVolunteerRecruit' : '${pageContext.request.contextPath}/updateVolunteerRecruit';
		$.ajax({
			url : url,
			type : "post",
			data : {
				vrId : vrId,
				recruitInfoTheme : recruitInfoTheme,
				recruitInfoPic : recruitInfoPic,
				recruitTel : recruitTel,
				recruitChargeName : recruitChargeName,
				recruitEndTimeStr : recruitEndTime,
				recruitInfoContent : recruitInfoContent,
				escapeState : escapeState,
				escapeClause : escapeClause
			},
			dataType : "json",
			success : function(data) {
				var result = data['result'];
				if (result === 1) {
					layer.msg('操作成功!', {
						icon : 1,
						time : 800
					});
					setTimeout(function() {
						$("#table").bootstrapTable('refresh');
						$("#modal").modal("hide");
					}, 1000);
				} else {
					layer.msg('操作失败!', {
						icon : 2,
						time : 800
					});
				}
				$("#closeBtn").button('reset');
			},
			error : function() {
				layer.msg('系统繁忙，请稍后再试!', {
					icon : 2,
					time : 800
				});
				$("#closeBtn").button('reset');
			}
		});

		return false;
	}

	//取消招募
	function cancelRecruit(id) {
		layer.confirm("是否要取消招募？", function(index) {
			$.ajax({
				url : "${pageContext.request.contextPath}/updateVolunteerRecruit",
				type : "post",
				data : {
					vrId : id,
					recruitState : 2
				},
				dataType : "json",
				success : function(data) {
					if (data.result == 1) {
						$("#table").bootstrapTable('refresh');
						layer.msg('操作成功!', {
							icon : 1,
							time : 800
						});
					} else {
						layer.msg('操作失败!', {
							icon : 2,
							time : 800
						});
					}
				},
				error : function() {
					layer.msg('系统繁忙，请稍后再试!', {
						icon : 5,
						time : 800
					});
				}
			});
		});
	}

	function fileChange() {
		//document.getElementById("upload_file_img").value = document.getElementById("imgFile").value;
		if (image_check('imgFile')) { //自己添加的文件后缀名的验证
			$.ajaxFileUpload({
				fileElementId : 'imgFile', //需要上传的文件域的ID，即<input type="file">的ID。
				url : "${pageContext.request.contextPath}/upload_img", //后台方法的路径
				type : 'post', //当要提交自定义参数时，这个参数要设置成post
				dataType : 'json', //服务器返回的数据类型。可以为xml,script,json,html。如果不填写，jQuery会自动判断。
				secureuri : false, //是否启用安全提交，默认为false。
				async : true, //是否是异步
				success : function(data) { //提交成功后自动执行的处理函数，参数data就是服务器返回的数据。
					imgUrl = data.url;
					$('#image').attr('src', '${pageContext.request.contextPath}/' + data.url);
					$("#image").show();
					$("#imgBtn").hide();
				}
			//                 error: function(data, status, e) {  //提交失败自动执行的处理函数。
			//                     console.error(e);
			//                 }
			});
		}
	}

	function Querry() {
		$("#table").bootstrapTable('refresh');
	}

	function image_check(feid) { //自己添加的文件后缀名的验证
		var img = document.getElementById(feid);
		return /.(jpg|png|gif|bmp)$/.test(img.value) ? true : (function() {
			layer.alert('图片格式仅支持jpg、png、gif、bmp格式，且区分大小写。');
			return false;
		})();
	}

	function exportData() {
		window.open("${pageContext.request.contextPath}/exportData?vrId=" + vrId, "_blank");
	}
</script>
</html>
